//
// Created by 李文龙 on 2019/11/30.
//

#ifndef ASYNC_TASK_POOL_TEST_COMMON_H
#define ASYNC_TASK_POOL_TEST_COMMON_H

#include <string>
#include <sys/time.h>
#include <chrono>
#include <iomanip>
#include <sstream>

#ifdef __cplusplus
#define NS_BEGIN                   namespace ilong {
#define NS_END                     }
#define USING_NS                   using namespace ilong;
#define NS                         ::ilong
#else
#define NS_BEGIN
#define NS_END
#define USING_NS
#define NS
#endif

static std::string GetFormatDate();

#define LOGTAG   "ILONG_LOG"

#define LOGD(format, ...)   		 printf("\033[34m %s %s %d %s DEBUG: " format "\n",GetFormatDate().c_str(),__FUNCTION__,__LINE__,LOGTAG, ##__VA_ARGS__)
#define LOGI(format, ...)   		 printf("\033[32m %s %s %d %s INFO: " format "\n",GetFormatDate().c_str(),__FUNCTION__,__LINE__,LOGTAG, ##__VA_ARGS__)
#define LOGW(format, ...)   		 printf("\033[33m %s %s %d %s WARNING: " format "\n",GetFormatDate().c_str(),__FUNCTION__,__LINE__,LOGTAG, ##__VA_ARGS__)
#define LOGE(format, ...)   		 printf("\033[31m %s %s %d %s ERROR: " format "\n",GetFormatDate().c_str(),__FUNCTION__,__LINE__,LOGTAG, ##__VA_ARGS__)

#define CALLBACK_0(__selector__,__target__, ...) std::bind(&__selector__,__target__, ##__VA_ARGS__)
#define CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__)
#define CALLBACK_2(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, ##__VA_ARGS__)
#define CALLBACK_3(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, ##__VA_ARGS__)

static std::string GetFormatDate()
{
    auto now = std::chrono::system_clock::now();
    auto timet = std::chrono::system_clock::to_time_t(now);
    auto localTime = *std::gmtime(&timet);
    auto ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now).time_since_epoch().count() % 1000;
    std::stringstream ss;
    std::string str;
    ss << std::put_time(&localTime, "%Y-%m-%dT%H:%M:%S") << "." << std::setfill('0') << std::setw(3) << ms;
    ss >> str;

    return str;
}


#endif //ASYNC_TASK_POOL_TEST_COMMON_H
